package com.zyy.smartcity1129.lifepay;

import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.zyy.smartcity1129.BaseFragment;
import com.zyy.smartcity1129.R;
import com.zyy.smartcity1129.data.IconInfo;
import com.zyy.smartcity1129.util.RvAd;

import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName: LPFragment$
 * @Description: 作用
 * @Author: letquit
 * @CreateDate: 7/12/2021$
 * @Version: 1.0
 */
public class LPFragment extends BaseFragment {
    private RecyclerView rvOnly;
    private Button btnNext;
    private Button btnMore;
    private TextView tvOnly;

    @Override
    protected int layId() {
        return R.layout.f_rv_only;
    }

    @Override
    protected String title() {
        return null;
    }

    @Override
    protected boolean back() {
        return false;
    }

    @Override
    protected Boolean bottom() {
        return null;
    }

    @Override
    protected void init(View iv) {
        LifePayFragment.mutableLiveData.postValue("自动缴费");
        initView(iv);
        List<IconInfo> list = new ArrayList<>();
        list.add(new IconInfo("水费缴费", R.drawable.water));
        list.add(new IconInfo("电费缴费", R.drawable.frie));
        list.add(new IconInfo("户号管理", R.drawable.me));
        list.add(new IconInfo("相关资讯", R.drawable.news));
        RvAd<IconInfo> rvAd = new RvAd<IconInfo>(list, R.layout.r_all) {
            private void initView(View vi) {
                image = (ImageView) vi.findViewById(R.id.image);
                tv1 = (TextView) vi.findViewById(R.id.tv1);
            }

            private TextView tv1;
            private ImageView image;

            @Override
            protected void initR(View vi, IconInfo allInfo, int p) {
                initView(vi);
                tv1.setText(allInfo.getName());
                Glide.with(getContext()).load(allInfo.getImg()).into(image);
                vi.setOnClickListener(view -> {
                    switch (allInfo.getName()) {
                        case "水费缴费":
                            add(new LPWaterFragment());
                            break;
                        case "电费缴费":
                            add(new LPElectricFragment());
                            break;
                        case "户号管理":
                            LifePayFragment.bottomLP.setSelectedItemId(R.id.lpAccount);
                            break;
                        case "相关资讯":
                            break;
                    }
                });
            }
        };
        rvOnly.setLayoutManager(new GridLayoutManager(getContext(), 4));
        rvOnly.setAdapter(rvAd);
    }

    private void initView(View iv) {
        rvOnly = (RecyclerView) iv.findViewById(R.id.rvOnly);
        btnNext = (Button) iv.findViewById(R.id.btnNext);
        btnMore = (Button) iv.findViewById(R.id.btnMore);
        tvOnly = (TextView) iv.findViewById(R.id.tvOnly);
    }
}
